//统一封装接口方法
import request from '@/utils/request'

export * from './ArticleDetailAPI'
import {
  getToken
} from '@/utils/storage'
//登录接口
export const loginAPI = ({
    mobile,
    code
  }) =>
  request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })

//用户 - 刷新token
export const getRefreshTokenAPI = () => request({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: 'Bearer ' + getStorage('refresh_token')
  }
})

//用户 - 关注作者
export const userFollowedAPI = ({
  userId
}) => request({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: {
    target: userId
  }
})

///用户 - 取关作者
export const userUnFollowedAPI = ({
  id
}) => request({
  url: `/v1_0/user/followings/${id}`,
  method: 'DELETE'
})

//用户 - 点赞
export const loveUserAPI = ({
  artId
}) => request({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target: artId
  }
})

//用户 - 取消点赞
export const noLoveUserAPI = ({
  artId
}) => request({
  url: `/v1_0/article/likings/${artId}`,
  method: 'DELETE'
})

//用户 - 获取个人资料
export const userProfileAPI = () => request({
  url: '/v1_0/user'
})

//用户 - 获取编辑用户页面个人信息
export const editUserProfileAPI = () => request({
  url: '/v1_0/user/profile'
})

//用户 - 修改用户头像
export const updateUserPhotoAPI = (fd) => request({
  url: '/v1_0/user/photo',
  method: 'PATCH',
  data: fd //fd外面一会传进来的new FormData（）表单对象
  //Content-Type:application/json;axios携带的,前提：data请求体是对象->json->发给后台
  //Content-Type:multipart/form-data;浏览器携带的，前提：data请求体必须FormData类型对象
})

//用户 - 编辑用户姓名
export const updateUserProfilesAPI = (obj) => request({
  url: '/v1_0/user/profile',
  method: 'PATCH',
  data: obj
})

//频道 - 获取所有频道
export const getAllChannelsAPI = () => request({
  url: '/v1_0/channels',
})

//频道 - 获取用户频道
export const getUserChannelsAPI = () => request({
  url: '/v1_0/user/channels',
})

//频道 - 更新用户频道
export const updateUserChannelsAPI = ({
  channels
}) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels
  }
})

//频道 - 删除频道
export const removeChannelAPI = ({
  channelId
}) => request({
  url: `/v1_0/user/channels/${channelId}`,
  method: 'DELETE'
})

//获取推荐文章
export const getArticleListAPI = ({
  channel_id,
  timestamp
}) => request({
  url: '/v1_0/articles',
  params: {
    channel_id,
    timestamp
  }
})

//反馈 - 文章 - 不感兴趣
export const disLikeArticleAPI = ({
  artId
}) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target: artId
  }
})

//反馈 - 举报
export const reportArticleAPI = ({
  artId,
  type
}) => request({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: {
    target: artId,
    type: type,
    remark: '---'
  }

})

//搜索 - 联想菜单列表
export const suggestListAPI = ({
  keywords
}) => request({
  url: '/v1_0/suggestion',
  params: {
    q: keywords
  }
})

//搜索 - 搜索结果列表
export const searchResultAPI = ({
  page = 1,
  q
}) => request({
  url: '/v1_0/search',
  params: {
    q,
    page
  }
})
